package com.qingxin.wuye.service;

import java.util.Date;

import org.springframework.stereotype.Service;

import com.qingxin.sys.entity.WxUser;
import com.qingxin.sys.mvc.SysError;
import com.qingxin.sys.service.BaseService;
import com.qingxin.sys.utils.StringUtils;
import com.qingxin.wuye.entity.WxUserRoomRel;
import com.qingxin.wuye.entity.WyRoom;

@Service
public class WxUserRoomRelService extends BaseService<WxUserRoomRel, String> {

	
	public synchronized SysError addWxUserRoomRel(String wxuserid, String roomid){
		if(StringUtils.isEmpty(wxuserid) || StringUtils.isEmpty(roomid)){
			return new SysError("参数错误");
		}
		
		Object id = getByHql("select id from WxUserRoomRel where wyRoom.roomid=?", roomid);
		if(id != null){
			return new SysError("房间已绑定其他账号.");
		}
		
		WxUserRoomRel rel = new WxUserRoomRel(new WxUser(wxuserid), new WyRoom(roomid), null, new Date());
		this.save(rel);
		return null;
	}
	
	
	
	public SysError delWxUserRoomRel(String wxuserid, String roomid){
		if(StringUtils.isEmpty(wxuserid) || StringUtils.isEmpty(roomid)){
			return new SysError("参数错误");
		}
		
		deleteByHql("delete from WxUserRoomRel where wxUser.wxuserid=? and wyRoom.roomid=?", wxuserid, roomid);
		return null;
	}
	
	
	
	
}
